﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Web;

using LitJson;

//namespace WebApplication2 {
	public static class Config {
		
		private static bool noCache = true;

		private static JsonData BuildItems() {
        var json = File.ReadAllText(HttpContext.Current.Server.MapPath("config.json"));
        return JsonMapper.ToObject(json);
    }

		private static JsonData _Items;

		public static JsonData Items{
			get{
				if (noCache || _Items == null){
					_Items = BuildItems();
				}
				return _Items;
			}
    }

		public static string[] GetStringList(string key) {
			List<string> _list = null;
			JsonData _jsonArr=Items[key];
			if (_jsonArr.IsArray) {
				foreach (JsonData _jsonArrItem in _jsonArr) {
					if (null == _list) { _list = new List<string>(); }
					_list.Add(_jsonArrItem.ToString());
				}
				return _list.ToArray();
			}
			return null;
		}

		public static string GetString(string key) {
			return Items[key].ToString();
		}

		public static int GetInt(string key) {
			return (int)Items[key];
		}
	}
//}